﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class PurchaseOrder
    {


        partial void Total_Compute(ref decimal result)
        {
            // Set result to the desired field value
            result = Quantity * Price;

        }

        partial void PurchaseOrder_Created()
        {
            Quantity = 1;
        }

        partial void Supply_Changed()
        {
            if (this.Supply != null)
            {
                this.Price = this.Supply.WholesalePrice;
                this.DeliveryDate = this.CreatedTime.AddDays(this.Supply.ShippingDays).Date;
            }
        }

        partial void IsClosed_Changed()
        {
            if (this.IsClosed == true)
                this.Supply.Drug.Stock += this.Quantity;
        }

        partial void IsClosed_IsReadOnly(ref bool result)
        {
            result = this.IsClosed == true;
        }
    }
}
